﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Values.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />

    <Style x:Key="MenuScrollButton" TargetType="{x:Type RepeatButton}">
        <Setter Property="ClickMode" Value="Hover" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border x:Name="ClassicBorder"
                            Background="{TemplateBinding Background}"
                            BorderThickness="1"
                            CornerRadius="{StaticResource Control.Border.CornerRadius}">
                        <ContentPresenter Margin="1"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}" TargetType="{x:Type ScrollViewer}">
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <RepeatButton Grid.Row="0"
                                      Grid.Column="0"
                                      Command="{x:Static ScrollBar.LineUpCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="false"
                                      Style="{StaticResource MenuScrollButton}">
                            <RepeatButton.Visibility>
                                <MultiBinding Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="0"
                                              FallbackValue="Visibility.Collapsed">
                                    <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Data="{StaticResource Arrow.Up.Simple}" Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
                        </RepeatButton>

                        <Border Grid.Row="1" Grid.Column="0">
                            <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
                        </Border>

                        <RepeatButton Grid.Row="2"
                                      Grid.Column="0"
                                      Command="{x:Static ScrollBar.LineDownCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="false"
                                      Style="{StaticResource MenuScrollButton}">
                            <RepeatButton.Visibility>
                                <MultiBinding Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="100"
                                              FallbackValue="Visibility.Collapsed">
                                    <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Data="{StaticResource Arrow.Up.Simple}" Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" RenderTransformOrigin="0.5,0.5" >
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform Angle="180"/>
                                        <TranslateTransform X="NaN" Y="NaN"/>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                        </RepeatButton>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>